﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCommon.Prompt;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZMCL.UI.PopWindows
{
    public partial class RiskDelay : EFViewCmes
    {
        public RiskDelay(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    this.fdRiskDate.IsReadOnly = true;
                    this.fdDeadlineDate.IsReadOnly = true;
                    base.Mode = OperationMode.Update;
                    break;
                case "detail":
                    this.Commit.Visibility = Visibility.Collapsed;
                    BaseTools.EFDataFieldNotEnabled(this.spWindows.GetChildObjects<EFDataField>(null, true));
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            string curDate = fdRiskDate.GetDataValue().ToString();
            if (fdDeadlineNew.Value != null)//判断解决日期是否输入合理
            {
                if (!fdDeadlineNew.Value.ToString().Equals(""))
                {
                    if (curDate.CompareTo(fdDeadlineNew.GetDataValue().ToString()) > 0)
                    {
                        Prompts pop = Prompts.getInstance();
                        pop.SetMsg("解决期限不能安排在隐患日期之前！");
                        pop.Show(6);
                        return;
                    }
                }
            }
            base.OnCommitButtonClick("ZMCL70", "delay", sender, e);//执行操作
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }
    }
}

